<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>社交活动平台 - 消息中心</title>
    <style>
        /* 重置样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
        }

        /* 容器样式 */
        .container {
            max-width: 480px;
            margin: 0 auto;
            background-color: #fff;
            min-height: 100vh;
        }

        /* 头部导航 */
        .header {
            position: sticky;
            top: 0;
            background-color: white;
            padding: 16px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
            z-index: 100;
        }

        .header-content {
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .back-btn {
            background: none;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: #333;
        }

        .header-title {
            font-size: 18px;
            font-weight: bold;
            flex-grow: 1;
            text-align: center;
        }

        .action-btn {
            background: none;
            border: none;
            font-size: 16px;
            color: #ff6b35;
            cursor: pointer;
        }

        /* 消息分类导航 */
        .message-nav {
            display: flex;
            background-color: #f9f9f9;
            border-bottom: 1px solid #eee;
        }

        .nav-item {
            flex: 1;
            text-align: center;
            padding: 16px 0;
            font-size: 14px;
            color: #999;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .nav-item.active {
            color: #ff6b35;
            font-weight: bold;
            position: relative;
        }

        .nav-item.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 2px;
            background-color: #ff6b35;
        }

        /* 消息列表 */
        .message-list {
            padding: 16px;
        }

        /* 消息项 */
        .message-item {
            display: flex;
            padding: 16px;
            border-bottom: 1px solid #eee;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .message-item:hover {
            background-color: #f9f9f9;
        }

        .message-item.unread {
            background-color: #fff8e1;
        }

        .message-avatar {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: #e0e0e0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            margin-right: 16px;
        }

        .message-content {
            flex-grow: 1;
        }

        .message-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 8px;
        }

        .message-title {
            font-weight: bold;
            color: #333;
            margin-bottom: 4px;
        }

        .message-time {
            font-size: 12px;
            color: #999;
        }

        .message-preview {
            font-size: 14px;
            color: #666;
            margin-bottom: 8px;
            line-height: 1.4;
        }

        .message-badge {
            display: inline-block;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #ff6b35;
            color: white;
            font-size: 12px;
            text-align: center;
            line-height: 20px;
        }

        /* 消息类型图标 */
        .message-icon {
            font-size: 20px;
            margin-right: 12px;
        }

        /* 空消息状态 */
        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #999;
        }

        .empty-icon {
            font-size: 60px;
            margin-bottom: 20px;
            color: #ddd;
        }

        .empty-title {
            font-size: 18px;
            margin-bottom: 8px;
        }

        .empty-description {
            font-size: 14px;
            margin-bottom: 20px;
        }

        /* 底部导航 */
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background-color: white;
            border-top: 1px solid #eee;
            display: flex;
            justify-content: space-around;
            padding: 12px 0;
            z-index: 100;
        }

        .nav-item-bottom {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: #9e9e9e;
            font-size: 12px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .nav-item-bottom.active {
            color: #ff6b35;
        }

        .nav-icon {
            font-size: 20px;
            margin-bottom: 4px;
        }

        /* 加载动画 */
        .loading {
            text-align: center;
            padding: 40px 20px;
        }

        .spinner {
            width: 36px;
            height: 36px;
            border: 4px solid #f3f3f3;
            border-top: 4px solid #ff6b35;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 弹窗样式 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            justify-content: center;
            align-items: center;
        }

        .modal-content {
            background-color: white;
            border-radius: 16px;
            width: 85%;
            max-width: 320px;
            padding: 24px;
            text-align: center;
            transform: translateY(20px);
            opacity: 0;
            transition: all 0.3s ease;
        }

        .modal.show {
            transform: translateY(0);
            opacity: 1;
        }

        .modal-title {
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 16px;
            color: #333;
        }

        .modal-message {
            margin-bottom: 24px;
            color: #666;
            line-height: 1.6;
        }

        .modal-actions {
            display: flex;
            gap: 12px;
        }

        .modal-btn {
            flex: 1;
            padding: 12px;
            border-radius: 8px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .cancel-btn {
            background-color: #f5f5f5;
            color: #666;
        }

        .confirm-btn {
            background: linear-gradient(135deg, #ff6b35 0%, #f9a825 100%);
            color: white;
        }

        /* 响应式适配 */
        @media (max-width: 480px) {
            .header-content {
                padding-top: 4px;
            }
            
            .message-item {
                padding: 12px;
            }
            
            .message-avatar {
                width: 40px;
                height: 40px;
            }
        }

        /* 动画效果 */
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .message-item {
            animation: fadeInUp 0.3s ease forwards;
        }

        /* 消息类型图标颜色 */
        .icon-activity { color: #ff6b35; }
        .icon-message { color: #45b7d1; }
        .icon-friend { color: #388e3c; }
        .icon-system { color: #9c27b0; }

        /* 通知角标样式 */
        .notification-badge {
            position: absolute;
            top: -4px;
            right: -4px;
            background-color: #ff6b35;
            color: white;
            border-radius: 50%;
            width: 18px;
            height: 18px;
            font-size: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        /* 消息分类标签 */
        .message-category {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 12px;
            margin-right: 8px;
        }

        .category-activity { background-color: #ffebee; color: #e53935; }
        .category-message { background-color: #e3f2fd; color: #1976d2; }
        .category-friend { background-color: #e8f5e9; color: #388e3c; }
        .category-system { background-color: #f3e5f5; color: #7b1fa2; }
    </style>
</head>
<body>
    <div class="container">
        <!-- 头部导航 -->
        <header class="header">
            <div class="header-content">
                <button class="back-btn" id="backBtn">←</button>
                <div class="header-title">消息中心</div>
                <button class="action-btn" id="clearBtn">清空</button>
            </div>
        </header>

        <!-- 消息分类导航 -->
        <div class="message-nav">
            <div class="nav-item active" data-category="all">全部</div>
            <div class="nav-item" data-category="activity">活动</div>
            <div class="nav-item" data-category="message">私信</div>
            <div class="nav-item" data-category="friend">好友</div>
        </div>

        <!-- 消息列表 -->
        <div class="message-list" id="messageList">
            <!-- 活动相关消息 -->
            <div class="message-item unread" data-message-id="1">
                <div class="message-avatar">🎉</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">活动报名确认</span>
                        <span class="message-time">10分钟前</span>
                    </div>
                    <p class="message-preview">您已成功报名参加"周末户外徒步活动"，请准时到场。</p>
                    <span class="message-category category-activity">活动提醒</span>
                </div>
            </div>

            <!-- 私信消息 -->
            <div class="message-item" data-message-id="2">
                <div class="message-avatar">👤</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">张小明</span>
                        <span class="message-time">1小时前</span>
                    </div>
                    <p class="message-preview">嗨，周末户外徒步活动你确定参加吗？</p>
                    <span class="message-category category-message">私信</span>
                </div>
            </div>

            <!-- 好友相关消息 -->
            <div class="message-item unread" data-message-id="3">
                <div class="message-avatar">👥</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">好友申请</span>
                        <span class="message-time">2小时前</span>
                    </div>
                    <p class="message-preview">李小红申请添加您为好友，通过后可以一起参加活动。</p>
                    <span class="message-category category-friend">好友</span>
                </div>
            </div>

            <!-- 系统消息 -->
            <div class="message-item" data-message-id="4">
                <div class="message-avatar">📢</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">系统通知</span>
                        <span class="message-time">昨天</span>
                    </div>
                    <p class="message-preview">平台新功能上线：活动评价系统，快来体验吧！</p>
                    <span class="message-category category-system">系统消息</span>
                </div>
            </div>

            <!-- 活动相关消息 -->
            <div class="message-item" data-message-id="5">
                <div class="message-avatar">📅</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">活动提醒</span>
                        <span class="message-time">昨天</span>
                    </div>
                    <p class="message-preview">您报名的"经典小说读书分享会"将在明天19:30开始。</p>
                    <span class="message-category category-activity">活动提醒</span>
                </div>
            </div>

            <!-- 私信消息 -->
            <div class="message-item" data-message-id="6">
                <div class="message-avatar">👨‍👩‍👧</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">王大力</span>
                        <span class="message-time">前天</span>
                    </div>
                    <p class="message-preview">周末的徒步活动我取消了，下次再约吧！</p>
                    <span class="message-category category-message">私信</span>
                </div>
            </div>

            <!-- 好友相关消息 -->
            <div class="message-item" data-message-id="7">
                <div class="message-avatar">❤️</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">好友动态</span>
                        <span class="message-time">前天</span>
                    </div>
                    <p class="message-preview">您的好友刘小美刚刚发布了新的活动。</p>
                    <span class="message-category category-friend">好友</span>
                </div>
            </div>

            <!-- 系统消息 -->
            <div class="message-item" data-message-id="8">
                <div class="message-avatar">⚙️</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">系统更新</span>
                        <span class="message-time">一周前</span>
                    </div>
                    <p class="message-preview">应用已更新至最新版本，体验更流畅！</p>
                    <span class="message-category category-system">系统消息</span>
                </div>
            </div>

            <!-- 活动相关消息 -->
            <div class="message-item unread" data-message-id="9">
                <div class="message-avatar">🔥</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">活动推荐</span>
                        <span class="message-time">一周前</span>
                    </div>
                    <p class="message-preview">根据您的兴趣，为您推荐了几个新的活动。</p>
                    <span class="message-category category-activity">活动提醒</span>
                </div>
            </div>

            <!-- 私信消息 -->
            <div class="message-item" data-message-id="10">
                <div class="message-avatar">🌟</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">李小红</span>
                        <span class="message-time">一周前</span>
                    </div>
                    <p class="message-preview">感谢参加上次的读书分享会，下次活动记得报名哦！</p>
                    <span class="message-category category-message">私信</span>
                </div>
            </div>

            <!-- 好友相关消息 -->
            <div class="message-item" data-message-id="11">
                <div class="message-avatar">🎉</div>
                <div class="message-content">
                    <div class="message-header">
                        <span class="message-title">好友互动</span>
                        <span class="message-time">两周前</span>
                    </div>
                    <p class="message-preview">您的好友张小明刚刚参与了您发起的活动。</p>
                    <span class="message-category category-friend">好友</span>
                </div>
            </div>
        </div>

        <!-- 底部导航 -->
        <nav class="bottom-nav">
            <div class="nav-item-bottom" data-page="home">
                <span class="nav-icon">🏠</span>
                <span>首页</span>
            </div>
            <div class="nav-item-bottom" data-page="search">
                <span class="nav-icon">🔍</span>
                <span>搜索</span>
            </div>
            <div class="nav-item-bottom" data-page="publish">
                <span class="nav-icon">➕</span>
                <span>发布</span>
            </div>
            <div class="nav-item-bottom active" data-page="profile">
                <span class="nav-icon">👤</span>
                <span>我的</span>
            </div>
        </nav>

        <!-- 加载状态 -->
        <div class="loading" id="loadingIndicator">
            <div class="spinner"></div>
            <p>加载中...</p>
        </div>

        <!-- 通知 Toast -->
        <div id="toast" style="display: none; position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background-color: #4caf50; color: white; padding: 12px 24px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 1001;"></div>
    </div>

    <script>
        // 全局变量
        let currentCategory = 'all';
        let unreadCount = 3; // 模拟未读消息数量

        // 初始化
        document.addEventListener('DOMContentLoaded', function() {
            initEventListeners();
            simulateLoading();
            
            // 更新未读消息角标
            updateNotificationBadge();
        });

        // 初始化事件监听器
        function initEventListeners() {
            // 返回按钮
            document.getElementById('backBtn').addEventListener('click', function() {
                window.history.back();
            });

            // 清空消息按钮
            document.getElementById('clearBtn').addEventListener('click', function() {
                showClearConfirmModal();
            });

            // 消息分类切换
            const navItems = document.querySelectorAll('.nav-item');
            navItems.forEach(item => {
                item.addEventListener('click', function() {
                    // 移除所有激活状态
                    navItems.forEach(i => i.classList.remove('active'));
                    // 添加当前激活状态
                    this.classList.add('active');
                    
                    currentCategory = this.dataset.category;
                    filterMessages();
                });
            });

            // 消息项点击
            const messageItems = document.querySelectorAll('.message-item');
            messageItems.forEach(item => {
                item.addEventListener('click', function() {
                    const messageId = this.dataset.messageId;
                    handleMessageClick(messageId);
                });
            });

            // 底部导航切换
            const navItemsBottom = document.querySelectorAll('.nav-item-bottom');
            navItemsBottom.forEach(item => {
                item.addEventListener('click', function() {
                    // 移除所有激活状态
                    navItemsBottom.forEach(i => i.classList.remove('active'));
                    // 添加当前激活状态
                    this.classList.add('active');
                    
                    const page = this.dataset.page;
                    handleNavigation(page);
                });
            });

            // 模拟消息更新
            setInterval(updateUnreadCount, 30000); // 每30秒检查一次
        }

        // 处理消息点击
        function handleMessageClick(messageId) {
            const messageItem = document.querySelector(`[data-message-id="${messageId}"]`);
            
            // 标记为已读
            if (messageItem.classList.contains('unread')) {
                messageItem.classList.remove('unread');
                unreadCount = Math.max(0, unreadCount - 1);
                updateNotificationBadge();
                
                // 显示成功提示
                showSuccessToast('消息已标记为已读');
            }
            
            // 显示消息详情（模拟）
            const title = messageItem.querySelector('.message-title').textContent;
            alert(`查看消息详情：${title}`);
        }

        // 消息分类筛选
        function filterMessages() {
            const messageItems = document.querySelectorAll('.message-item');
            
            if (currentCategory === 'all') {
                messageItems.forEach(item => {
                    item.style.display = 'flex';
                });
            } else {
                messageItems.forEach(item => {
                    const categoryClass = Array.from(item.classList).find(cls => cls.startsWith('category-'));
                    if (categoryClass && categoryClass.includes(currentCategory)) {
                        item.style.display = 'flex';
                    } else {
                        item.style.display = 'none';
                    }
                });
            }
        }

        // 显示清空确认弹窗
        function showClearConfirmModal() {
            if (confirm('确定要清空所有消息吗？')) {
                clearAllMessages();
            }
        }

        // 清空所有消息
        function clearAllMessages() {
            showLoading();
            
            setTimeout(() => {
                hideLoading();
                
                // 隐藏所有消息项
                const messageItems = document.querySelectorAll('.message-item');
                messageItems.forEach(item => {
                    item.style.display = 'none';
                });
                
                // 重置未读计数
                unreadCount = 0;
                updateNotificationBadge();
                
                // 显示空状态
                showEmptyState();
                
                showSuccessToast('消息已清空');
            }, 1500);
        }

        // 显示空状态
        function showEmptyState() {
            const messageList = document.getElementById('messageList');
            
            // 如果没有消息，显示空状态
            const visibleItems = Array.from(messageList.querySelectorAll('.message-item')).filter(item => 
                item.style.display !== 'none'
            );
            
            if (visibleItems.length === 0) {
                messageList.innerHTML = `
                    <div class="empty-state">
                        <div class="empty-icon">📭</div>
                        <h3 class="empty-title">暂无消息</h3>
                        <p class="empty-description">您还没有收到任何消息通知</p>
                    </div>
                `;
            }
        }

        // 更新未读消息计数
        function updateUnreadCount() {
            // 模拟随机更新未读消息（实际应用中应该从服务器获取）
            const randomChange = Math.floor(Math.random() * 3) - 1; // -1, 0, 或 1
            unreadCount = Math.max(0, unreadCount + randomChange);
            
            if (unreadCount > 0) {
                updateNotificationBadge();
            }
        }

        // 更新通知角标
        function updateNotificationBadge() {
            const badge = document.querySelector('.notification-badge');
            
            if (badge) {
                badge.textContent = unreadCount > 0 ? unreadCount : '';
                badge.style.display = unreadCount > 0 ? 'flex' : 'none';
            }
        }

        // 处理导航切换
        function handleNavigation(page) {
            switch(page) {
                case 'home':
                    alert('跳转到首页');
                    break;
                case 'search':
                    alert('跳转到搜索页面');
                    break;
                case 'publish':
                    alert('跳转到发布页面');
                    break;
                case 'profile':
                    // 个人中心无需特殊处理
                    break;
            }
        }

        // 显示加载状态
        function showLoading() {
            const loading = document.getElementById('loadingIndicator');
            loading.style.display = 'block';
        }

        // 隐藏加载状态
        function hideLoading() {
            const loading = document.getElementById('loadingIndicator');
            loading.style.display = 'none';
        }

        // 模拟加载效果
        function simulateLoading() {
            showLoading();
            setTimeout(() => {
                hideLoading();
            }, 1500);
        }

        // 显示成功提示
        function showSuccessToast(message) {
            const toast = document.getElementById('toast');
            toast.textContent = message;
            toast.style.display = 'block';
            
            // 3秒后自动隐藏
            setTimeout(() => {
                toast.style.display = 'none';
            }, 3000);
        }

        // 添加触摸反馈效果
        const buttons = document.querySelectorAll('button');
        buttons.forEach(button => {
            button.addEventListener('touchstart', function() {
                this.style.transform = 'scale(0.95)';
            });
            
            button.addEventListener('touchend', function() {
                this.style.transform = 'scale(1)';
            });
        });

        // 添加页面滚动效果
        let lastScrollTop = 0;
        window.addEventListener('scroll', function() {
            const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
            
            // 隐藏/显示底部导航
            const bottomNav = document.querySelector('.bottom-nav');
            if (scrollTop > lastScrollTop && scrollTop > 100) {
                bottomNav.style.transform = 'translateY(100%)';
            } else {
                bottomNav.style.transform = 'translateY(0)';
            }
            
            lastScrollTop = scrollTop;
        });

        // 添加返回顶部功能
        window.addEventListener('scroll', function() {
            if (window.pageYOffset > 300) {
                // 可以添加返回顶部按钮
            }
        });

        // 模拟消息更新（用于演示）
        setTimeout(() => {
            const messageItems = document.querySelectorAll('.message-item');
            // 模拟添加新消息
            if (messageItems.length > 0) {
                const newMessage = document.createElement('div');
                newMessage.className = 'message-item unread';
                newMessage.dataset.messageId = messageItems.length + 1;
                newMessage.innerHTML = `
                    <div class="message-avatar">🔔</div>
                    <div class="message-content">
                        <div class="message-header">
                            <span class="message-title">新消息提醒</span>
                            <span class="message-time">刚刚</span>
                        </div>
                        <p class="message-preview">您收到了一条新消息，请及时查看。</p>
                        <span class="message-category category-system">系统消息</span>
                    </div>
                `;
                
                document.getElementById('messageList').insertBefore(newMessage, messageItems[0]);
                unreadCount++;
                updateNotificationBadge();
            }
        }, 5000);
    </script>
</body>
</html>
